package com.weishe.loc;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

import org.apache.hadoop.io.WritableComparable;

public class Loc implements WritableComparable<Loc> {
	public static Calendar c = Calendar.getInstance();
	private String imei;
	private String loc;
	private long time;
	private int hours;

	@Override
	public void readFields(DataInput input) throws IOException {
		this.loc = input.readUTF();
		this.time = input.readLong();
	}

	@Override
	public void write(DataOutput output) throws IOException {
		output.writeUTF(loc);
		output.writeLong(time);
	}

	@Override
	public int compareTo(Loc loc) {
		return Long.compare(time, loc.getTime());
	}

	public String getLoc() {
		return loc;
	}

	public void setLoc(String loc) {
		this.loc = loc;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
		// 同时计算出时间段
		c.setTimeInMillis(time);
		int hour = c.get(Calendar.HOUR);
		if (hour < 9) {
			this.hours = 9;
		}
		if (9 <= hour && hour < 17) {
			this.hours = 17;
		}
		if (17 <= hour && hour < 24) {
			this.hours = 24;
		}
	}

	public int getHours() {
		return hours;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

}
